import http from '@/utils/http'

const BASE_URL = '/settlement/report'

export interface SettlementResp {
    id: string
    payDateStart: string
    payDateEnd: string
    platform: string
    song: string
    singer: string
    album: string
    cpInto: string
    channel: string
    belongTo: string
    status: string
    createUserString: string
    updateUserString: string
    disabled: boolean
}

export interface SettlementDetailResp {
    id: string
    payDate: string
    payDateStart: string
    payDateEnd: string
    platform: string
    song: string
    singer: string
    album: string
    cpInto: string
    channel: string
    belongTo: string
    belongToName: string
    status: string
    createUser: string
    createTime: string
    updateUser: string
    updateTime: string
    createUserString: string
    updateUserString: string
}

export interface SettlementQuery {
    platform: string | undefined
    channel: string | undefined
    song: string | undefined
    status: string | undefined
    payDateStart?: string
    payDateEnd: string | undefined
    belongTo: string | undefined
    sort: Array<string>
}

export interface SettlementPageQuery extends SettlementQuery, PageQuery {
    userId: string | undefined
}

/** @desc 查询结算管理列表 */
export function listSettlement(query: SettlementPageQuery) {
    query.userId = query.belongTo
    return http.get<PageRes<SettlementResp[]>>(BASE_URL, query)
}

/** @desc 查询结算管理列表根据userId查询 */
export function listSettlementByUserId(id: string, query: SettlementPageQuery) {
    query.userId = id
    return http.get<PageRes<SettlementResp[]>>(BASE_URL, query)
}

/** @desc 批量修改结算管理 */
export function updateSettlementFlagByUserId(id: string) {
    return http.put(`${BASE_URL}/update/list/${id}`)
}

/** @desc 查询结算管理列表根据userId查询 */
export function listSettlementByUserIdMyself(query: SettlementPageQuery) {
    return http.get<PageRes<SettlementResp[]>>(`${BASE_URL}/myself`, query)
}

/** @desc  */
export function downloadBill(query: SettlementPageQuery) {
    return http.download(`${BASE_URL}/download/bill`, query)
}

/** @desc 对结算数据进行结算标记 */
export function dealSettlementFlagByUserId(settlementIds: Array<string | number>) {
    return http.del(`/mark`, settlementIds)
}

/** @desc 查询结算管理详情 */
export function getSettlement(id: string) {
    return http.get<SettlementDetailResp>(`${BASE_URL}/${id}`)
}

/** @desc 新增结算管理 */
export function addSettlement(data: any) {
    return http.post(BASE_URL, data)
}

/** @desc 修改结算管理 */
export function updateSettlement(data: any, id: string) {
    return http.put(`${BASE_URL}/${id}`, data)
}

/** @desc 删除结算管理 */
export function deleteSettlement(id: string) {
    return http.del(BASE_URL, {ids: [id]})
}

/** @desc 导出结算管理 */
export function exportSettlement(query: SettlementQuery) {
    return http.download(`${BASE_URL}/export`, query)
}

/** @desc 下载结算导入模板 */
export function downloadSettlementImportTemplate() {
    return http.download(`${BASE_URL}/import/template`)
}

/** @desc 解析结算导入数据 */
export function parseImportSettlement(data: FormData) {
    return http.post(`${BASE_URL}/import/parse`, data)
}

/** @desc 导入结算 */
export function importSettlement(data: any) {
    return http.post(`${BASE_URL}/import`, data)
}

/** @desc 同步报表音乐人归属绑定 */
export function updateSettlementBelongTo(data: Array<string>, id: string) {
    return http.put(`${BASE_URL}/updateSettlementBelongTo/${id}`, data)
}

/** @desc 同步报表状态 */
export function updateSettlementStatus(id: string) {
    return http.put(`${BASE_URL}/updateSettlementStatus/${id}`)
}

